#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Módulos 
import sys, gtk, pygame, utils, objetos
from pygame.locals import *

# Constantes

# Clases
# ---------------------------------------------------------------------
    
class Linea:
	def __init__(self):
		
		self.linea,self.linea_rect
		self.posx_fin = posx
		self.posy_fin = posy        
   

# ---------------------------------------------------------------------
def dibujar(screen,cursor_picture, clock):
    salir = 0
    background_image = utils.load_image('images/fondo_3.jpg')
    i= 0
    j= 0
    numero_linea = 1
    btn_adelante = objetos.BotonAdelante()
    btn_atras = objetos.BotonAtras()
    
    
    clase, clase_rect = utils.texto_clase("Clase 3", 740*utils.RES, 30*utils.RES)
           
    linea1,linea1_rect = utils.texto_chico('Hola Detectives', 600*utils.RES,270*utils.RES)
    linea2,linea2_rect = utils.texto_chico('vean el indicador', 600*utils.RES,285*utils.RES)
    linea3,linea3_rect = utils.texto_chico('del basurómetro', 600*utils.RES,300*utils.RES)
    linea4,linea4_rect = utils.texto_chico('¡No hay tiempo', 600*utils.RES,315*utils.RES)
    linea5,linea5_rect = utils.texto_chico('que perder!', 600*utils.RES,330*utils.RES)
    linea6,linea6_rect = utils.texto_chico('¿Qué podemos hacer?', 600*utils.RES,345*utils.RES)
    trueno = utils.load_image('images/c3_2trueno.jpg',True)
    beto = utils.load_image('images/c3_2beto.jpg',True)
    dialogo_beto = utils.load_image('images/c3_2betodialogo.jpg')
    dialogo_trueno = utils.load_image('images/c3_2truenodialogo.jpg')
    impresora = utils.load_image('images/c3_2impresora.jpg')
    frame = 0
    sonido_impresora = pygame.mixer.Sound("sounds/impresora.ogg")
    sonido_impresora.set_volume(0.2)   
    sonido_impresora.play()	
    
    while salir == 0:
    
    	# Pump GTK messages.
		while gtk.events_pending():
			gtk.main_iteration()
			
		for eventos in pygame.event.get():
			if eventos.type == QUIT:
				sys.exit(0)
			elif eventos.type == pygame.VIDEORESIZE:
			   pygame.display.set_mode(eventos.size, pygame.RESIZABLE)	
			elif eventos.type == MOUSEBUTTONDOWN:
				if btn_adelante.rect.collidepoint(pygame.mouse.get_pos()):
					salir = 3
					btn_adelante.sonido.play()	
				elif btn_atras.rect.collidepoint(pygame.mouse.get_pos()):
					salir = 1
					btn_atras.sonido.play()	
				elif betoytrueno.rect.collidepoint(pygame.mouse.get_pos()):
					if show_dialog == False:
						show_dialog = True
					else:
						show_dialog = False

		# Realiza la animacion del texto				
			
		screen.blit(background_image, (0, 0))
		screen.blit(clase, clase_rect)
		if frame > 130:
			sonido_impresora.stop()
			screen.blit(beto, (70*utils.RES, 100*utils.RES))
			screen.blit(trueno, (220*utils.RES, 300*utils.RES))
		if frame > 160:
			screen.blit(dialogo_beto, (int(250*utils.RES), int(50*utils.RES)))
		if frame > 200:
			screen.blit(dialogo_trueno, (int(270*utils.RES), int(200*utils.RES)))
		screen.blit(impresora, (450*utils.RES, 100*utils.RES))
		if frame > 10:
			screen.blit(linea1,linea1_rect)
		if frame > 30:
			screen.blit(linea2,linea2_rect)
		if frame > 50:
			screen.blit(linea3,linea3_rect)
		if frame > 70:
			screen.blit(linea4,linea4_rect)
		if frame > 90:
			screen.blit(linea5,linea5_rect)
		if frame > 110:
			screen.blit(linea6,linea6_rect)
		screen.blit(btn_adelante.image, btn_adelante.rect)
		screen.blit(btn_atras.image, btn_atras.rect)
		screen.blit(cursor_picture, pygame.mouse.get_pos())
		pygame.display.flip()

		# Try to stay at 30 FPS
		clock.tick(30)
		frame = frame +1
    sonido_impresora.stop()            	 
    return salir

# This function is called when the game is run directly from the command line:
# ./TestGame.py 
def main():
	
	pygame.init()
	screen = pygame.display.set_mode((int(800*utils.RES), int(520*utils.RES)), pygame.RESIZABLE) #pygame.display.get_surface() #

	# Fake a Sugar cursor for the pyGame canvas area
	pygame.mouse.set_cursor((8,8),(0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0))
	cursor_picture = pygame.image.load('images/standardcursor.png')
	cursor_picture.convert_alpha() 
	clock = pygame.time.Clock()
	dibujar(screen,cursor_picture,clock)

if __name__ == '__main__':
   main()
